{include file="public/head"}
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">会员管理</a>
        <a>
          <cite>会员删除与恢复</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5">
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input"  autocomplete="off" placeholder="开始日" name="start" id="start">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input"  autocomplete="off" placeholder="截止日" name="end" id="end">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="username"  placeholder="请输入用户名" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-header">
                        <button class="layui-btn layui-btn-warm" onclick="resumeAll()"><i class="layui-icon layui-icon-refresh-1"></i>批量恢复</button>
                        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon layui-icon-delete"></i>批量删除</button>
                    </div>
                    <div class="layui-card-body ">
                        <table class="layui-table layui-form">
                          <thead>
                            <tr>
                              <th>
                                <input type="checkbox" lay-filter="checkall" name="" lay-skin="primary">
                              </th>
                              <th>ID</th>
                              <th>用户名</th>
                              <th>姓名</th>
                              <th>性别</th>
                              <th>手机</th>
                              <th>邮箱</th>
                              <th>地址</th>
                              <th>加入时间</th>
                              <th>状态</th>
                              <th>操作</th></tr>
                          </thead>
                          <tbody>
                            {volist name="data" id="vo"}
                            <tr>
                              <td>
                                <input type="checkbox" name="id" value="{$vo.id}"   lay-skin="primary">

                              </td>
                              <td>{$vo.id}</td>
                              <td>{$vo.username}

                              </td>
                              <td>{$vo.realname}</td>
                              <td>{$vo.sex}</td>
                              <td>{$vo.mobile}</td>
                              <td>{$vo.email}</td>
                              <td>浙江省天台县</td>
                              <td>{$vo.reg_time|date="Y-m-d H:i"}</td>
                              <td class="td-status">
                                已删除
                               </td>

                              <td class="td-manage">
                                <a title="恢复" onclick="member_resume(this,'{$vo.id}')" href="javascript:;">
                                  <i class="layui-icon layui-icon-refresh" style="font-size: 20px; color: #1E9FFF;"></i>

                                 <a title="删除" onclick="member_del(this,'{$vo.id}')" href="javascript:;">
                                  <i class="layui-icon layui-icon-delete" style="font-size: 20px; color: #FF5722;"></i>
                                </a>
                                </a>
                               
                              </td>
                            </tr>
                            {/volist}
   
                          </tbody>
                        </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            <div>
                              <a class="prev" href="">&lt;&lt;</a>
                              <a class="num" href="">1</a>
                              <span class="current">2</span>
                              <a class="num" href="">3</a>
                              <a class="num" href="">489</a>
                              <a class="next" href="">&gt;&gt;</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div> 
    <script>
      layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var  form = layui.form;
        
        // 监听全选
        form.on('checkbox(checkall)', function(data){

          if(data.elem.checked){
            $('tbody input').prop('checked',true);
          }else{
            $('tbody input').prop('checked',false);
          }
          form.render('checkbox');
        }); 

        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
      });

 //点击"删除"后，打开信息层
   function  member_del(obj,id){
     layui.use('layer',function(){
        layer.confirm('是否确定删除？',{
            btn:['确定','取消'],
            // btnAlign:'c', //按钮居中对齐
            // shade:[0.3,'green'],  //遮罩效果，0.5是不透明度，范围[0,1], 参数2是背景颜色
            yes:function(index){
               //按钮1，即确定按钮的回调函数
             //  console.log('确定,索引:'+index); 
               //发送异步请求
               $.ajax({
                url : '/admin/member/delbyid',
                type : 'post',
                //指定要发给服务器的参数,
                data : {"id": id,"action":"del"},
                dataType : 'json',
                success : function(data) {
                  //console.log(data+',type:'+typeofdata);
                  //js会隐式调用Boolean()将'true'转换为true
                  if(data){
                    //关闭弹出层,信息层就是当前窗口的层直接关闭
                    layer.close(index);
                    $(obj).parents("tr").remove();
                    layer.msg(data.msg,{icon:1,time:2000});
                  }     
                  
                },
                error: function (xhr, textStatus, errorThrown) {
                  layer.close(index);//关闭弹出层
                 
                  var data=JSON.parse(xhr.responseText);//以json方式解释data
                  var msg=data.message;//取得错误消息

                  layer.msg(msg, {icon:2,time:2000});//弹出错误提示
                  // alert("数据异常");
                },
                // complete:function(xhr,textStatus){
                //       //重新请求列表页面                      
                //       location.href='/admin/member/del';                      
                // }  
               });
            },
            resize:false,   //不允许拉伸层，即不能改变层的大小
            btn2:function(index){
                //按钮【取消】的回调
                //console.log('取消，索引：'+index)
                // return false //开启该代码可禁止点击该按钮关闭
          }
        });
     });
   }


            /*用户-删除*/
      function member_resume(obj,id){
          layer.confirm('确认要恢复吗？',function(index){
              //发异步删除数据
              $(obj).parents("tr").remove();
              layer.msg('恢复成功!',{icon:1,time:1000});
          });
      }



      function resumeAll (argument) {       
        var ids = [];
        // 获取选中的id 
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
               ids.push($(this).val())
            }
        });
  
        layer.confirm('确认要恢复吗？'+ids.toString(),function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('恢复成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
      }
      function delAll (argument) {       
        var ids = [];
        // 获取选中的id 
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
               ids.push($(this).val())
            }
        });
  
        layer.confirm('确认要删除吗？删除后将无法恢复！'+ids.toString(),function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('恢复成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
      }
    </script>

  </body>

</html>